<template>
    <div class="variableediting">
        <div class="topcon">
                <div class="left-nav">
                     <div :class="['nav-item', {'active':tabindex == 1}]" @click="tabindex = 1">变量管理</div>
                     <div :class="['nav-item', {'active':tabindex == 2}]"  @click="tabindex = 2">批量编辑</div>
                     <!-- #2178F1 -->
                </div>
                <div class="right-btn" v-show="tabindex == 1">
                    <div class="btn-item" @click="addDecivebianfn">添加变量</div>
                    <!-- <div class="btn-item item1">导入变量</div> -->
                </div>
        </div>
        <div class="con">
             <div class="left-tree">
                 <el-scrollbar style="height:calc(100% - 30px);width: 100%;">
                    <!-- default-expand-all -->
                        <!-- highlight-current -->
                        <!-- node-key="id" :props="defaultProps"   ref="tree"  -->
                        <!-- @node-click="treeClick" -->
                    <el-tree class="filter-tree" 
                        :data="dataList"
                        default-expand-all
                        node-key="myid"
                        highlight-current
                        :props="defaultProps"
                        @node-click="treeClick"
                    >
                    <template #default="{ node }">
                        <div class="custom-tree-node" >
                             <div class="flexitem">
                                 <img src="../assets/btnImg/2.1.png" alt="" v-if="node.data.mytype == 'device'">
                                 <img src="../assets/btnImg/group.png" alt="" v-else>
                                 {{ node.label }}
                            </div>
                        </div>
                    </template>
                    </el-tree>
                    </el-scrollbar>
             </div>
             <div class="right-table" v-show="tabindex == 1" style="padding-right:12px">
                 <div class="mi-table">
                      <el-table :data="leftTable" height="100%" stripe  style="width: 100%;" >
                                        <el-table-column type="index"  width="60" label="序号" align="center"> </el-table-column>
                                        <!-- <el-table-column prop="dianhao"  width="60" label="点号" align="center"> </el-table-column> -->
                                        <el-table-column prop="name" mim-width="120" label="变量名称"> </el-table-column>
                                        <el-table-column prop="fullName" mim-width="120" label="变量全名"> </el-table-column>
                                        <el-table-column prop="data_number" width="120" label="点号" align="center"> </el-table-column>
                                        <!-- <el-table-column prop="quanming" min-width="140" label="变量全名"> </el-table-column> -->
                                        <el-table-column prop="data_type_name" mim-width="180" label="数据类型">
                                                 <!-- <template #default="{row}">
                                                    <div>
                                                         <el-select v-model="row.data_type" placeholder="请选择" style="width:100%">
                                                                <el-option
                                                                v-for="item in optionsType"
                                                                :key="item.value"
                                                                :label="item.name"
                                                                :value="item.value">
                                                                </el-option>
                                                        </el-select>
                                                    </div>
                                                </template> -->
                                        </el-table-column>
                                        <el-table-column prop="access_name" width="120" label="访问"> 
                                              <!-- <template #default="{row}">
                                                    <div>
                                                         <el-select v-model="row.access" placeholder="请选择" style="width:90px">
                                                            <el-option
                                                            v-for="item in optionsFang"
                                                            :key="item.value"
                                                            :label="item.name"
                                                            :value="item.value">
                                                            </el-option>
                                                        </el-select>
                                                    </div>
                                                </template> -->
                                        </el-table-column>
                                        <el-table-column prop="coefficient" width="120" label="转换系数"></el-table-column>
                                        <el-table-column  width="100" label="是否锁定" align="center"> 
                                             <template #default="{row}">
                                                    <div class="mysort">
                                                        <!-- <el-checkbox v-model="row.lock"></el-checkbox> -->
                                                        {{row.lock ? '是' : '否'}}
                                                    </div>
                                                </template>
                                        </el-table-column>
                                        <el-table-column prop="value" width="90" label="设定值"> </el-table-column>
                                        <el-table-column  mim-width="120" label="操作" fixed="right" align="center"> 
                                             <template #default="{row}">
                                                    <div class="mysort">
                                                        <el-tooltip class="item" effect="dark" content="编辑" placement="top">
                                                           <img src="../assets/btnImg/edit2.png" alt="" style="margin-right:20px" @click.stop="editFN(row)">
                                                        </el-tooltip>
                                                        <el-tooltip class="item" effect="dark" content="删除" placement="top">
                                                            <img src="../assets/btnImg/del2.png" alt="" @click="delVariablesfn(row)">
                                                        </el-tooltip>
                                                           
                                                           
                                                    </div>
                                                </template>
                                        </el-table-column>
                    </el-table>
                </div>
                <div class="bot-btn">
                     <el-scrollbar style="height:100%;width: 100%;">
                           <div class="scr-div">
                            <div class="left-btn">
                               
                            </div>
                            <div class="right-paging">
                                <el-pagination @size-change="handleSizeChangejiao" @current-change="handleCurrentChangejiao" background
                                        :current-page="currentPage" :page-sizes="[100]" :page-size="100"
                                        layout="total, sizes, prev, pager, next" :total="total">
                                        </el-pagination>
                            </div>
                           </div>
                      </el-scrollbar>
                </div>
             </div>
             <div class="right-table" v-show="tabindex == 2">
                    <div class="top-search">
                        
                                <div class="search-item"> 
                                    <div class="leftname">名称匹配</div>
                                    <el-input v-model="search.device_name" style="width:200px" />
                                </div>
                                <div class="search-item"> 
                                    <div class="leftname">应用类型组</div>
                                  <el-select v-model="search.app_type_group" filterable placeholder="请选择"  @change="getApplicationTypefn(search.app_type_group);search.app_type = ''">
                                                    <el-option
                                                        v-for="item in typeGroup"
                                                        :key="item.code"
                                                        :label="item.name"
                                                        :value="item.code"
                                                    ></el-option>
                                   </el-select>
                                </div>
                                <div class="search-item"> 
                                    <div class="leftname">应用类型</div>
                                    <el-select v-model="search.app_type" filterable placeholder="请选择">
                                                    <el-option
                                                        v-for="item in yingdataTypeList"
                                                        :key="item.code"
                                                        :label="item.name"
                                                        :value="item.code"
                                                    ></el-option>
                                    </el-select>
                                </div>
                                    <div class="btn-item" @click="searchFN">搜索</div>
                                    <div class="btn-item item1" @click="chongzhifn">重置</div>
    
                    </div>
                    <div class="lines"></div>
                     <div class="mi-table" style="height: calc(100% - 90px);padding:0px 12px;margin-left: 0px;">
                            <el-table :data="leftTable" max-height="100%" stripe  style="width: 100%;" @selection-change="handleSelectionChange">
                                  <el-table-column type="selection" width="55" align="center"> </el-table-column>
                                                <el-table-column type="index"  width="60" label="序号" align="center"> </el-table-column>
                                                <el-table-column prop="name"  min-width="120" label="变量名称"> </el-table-column>
                                                <!-- <el-table-column prop="fullName" mim-width="120" label="变量全名"> </el-table-column> -->
                                                <el-table-column prop="value" width="90" label="当前值"> </el-table-column>
                                                <el-table-column prop="max_value" width="90" label="最大合理值"> </el-table-column>
                                                <el-table-column prop="min_value" width="90" label="最小合理值"> </el-table-column>
                                                <el-table-column prop="coefficient" width="90" label="转换系数"> </el-table-column>
                                                <el-table-column prop="offset" width="90" label="偏移量"> </el-table-column>
                                                <el-table-column prop="zero" width="90" label="零死区"> </el-table-column>
                                                <el-table-column prop="data_type_name" width="90" label="数据类型"> </el-table-column>
                                                <el-table-column prop="app_type_group_name" min-width="90" label="应用类型组"> </el-table-column>
                                                <el-table-column prop="app_type_name" min-width="90" label="应用类型"> </el-table-column>
                                                <!-- <el-table-column prop="fangqian" width="90" label="存储周期"> </el-table-column> -->
                            </el-table>
                       </div>
                      <div class="bot-btn">
                     <el-scrollbar style="height:calc(100%);width: 100%;">
                           <div class="scr-div">
                            <div class="left-btn">
                                <div class="btn-items qi-btn" style="margin:0px 12px" @click="openPiliangEdit">批量修改 <img src="../assets/btnImg/editbtn.png"></div>
                                <div class="btn-items del-btn" @click="delMordfn">批量删除 <img src="../assets/btnImg/del2.png"></div>
                            </div>
                            <div class="right-paging">
                                <el-pagination @size-change="handleSizeChangejiao" @current-change="handleCurrentChangejiao" background
                                        :current-page="currentPage" :page-sizes="[100]" :page-size="100"
                                        layout="total, sizes, prev, pager, next" :total="total">
                                        </el-pagination>
                            </div>
                           </div>
                      </el-scrollbar>
                </div>
             </div>
              <div class="el-loading-mask" v-show="isMask">
             <div class="el-loading-spinner"><svg viewBox="25 25 50 50" class="circular"> <circle cx="50" cy="50" r="20" fill="none" class="path"></circle></svg></div>
          </div>
        </div>
        
        <!-- 新增/修改变量 -->
        <el-dialog width="1000px" draggable  :title="deviceTypecaozuo" :close-on-click-modal='false' v-model="addDecivebian">
                    <div class="addDecivebian">
                        <div class="xiaotitle">
                             <span></span>基础属性
                        </div>
                        <div class="leftandrightdialog">
                            <div class="leftdio" style="margin-right:20px">
                                <div class="items">
                                    <div class="leftname"><span>*</span> 变量名称：</div>
                                    <el-input v-model="variableParameter.name" ></el-input>
                                </div>
                                <div class="items">
                                    <div class="leftname"><span>*</span> 设定值：</div>
                                    <el-input v-model="variableParameter.value" ></el-input>
                                </div>
                                <div class="items">
                                    <div class="leftname"><span>*</span> 最大合理值：</div>
                                    <el-input v-model="variableParameter.max_value" ></el-input>
                                </div>
                                <div class="items">
                                    <div class="leftname"><span>*</span> 最小合理值：</div>
                                    <el-input v-model="variableParameter.min_value" ></el-input>
                                </div>
                                <div class="items">
                                    <div class="leftname"><span>*</span> 转换系数：</div>
                                    <el-input v-model="variableParameter.coefficient" ></el-input>
                                </div>
                                
                                <div class="items">
                                        <div class="leftname"><span>*</span> 访问：</div>
                                        <el-select v-model="variableParameter.access" placeholder="请选择">
                                                                <el-option
                                                                v-for="item in optionsFang"
                                                                :key="item.value"
                                                                :label="item.name"
                                                                :value="item.value">
                                                                </el-option>
                                        </el-select>
                                </div>
                                <div class="items">
                                    <div class="leftname"><span>*</span> 锁定：</div>
                                    <el-checkbox v-model="variableParameter.lock"></el-checkbox>
                                </div>
                            


                            </div>
                            <div class="leftdio">
                                <div class="items">
                                    <div class="leftname"><span>*</span> 数据类型：</div>
                                    <el-select v-model="variableParameter.data_type" placeholder="请选择">
                                                    <el-option
                                                        v-for="item in optionsType"
                                                        :key="item.value"
                                                        :label="item.name"
                                                        :value="item.value"
                                                    ></el-option>
                                                </el-select>
                                </div>
                                <div class="items">
                                    <div class="leftname"><span>*</span> 应用类型组：</div>
                                    <el-select v-model="variableParameter.app_type_group" filterable placeholder="请选择"  @change="getApplicationTypefn(variableParameter.app_type_group);variableParameter.app_type = ''">
                                                    <el-option
                                                        v-for="item in typeGroup"
                                                        :key="item.code"
                                                        :label="item.name"
                                                        :value="item.code"
                                                    ></el-option>
                                                </el-select>
                                </div>
                                <div class="items">
                                    <div class="leftname"><span>*</span> 应用类型：</div>
                                    <el-select v-model="variableParameter.app_type" filterable placeholder="请选择">
                                                    <el-option
                                                        v-for="item in yingdataTypeList"
                                                        :key="item.code"
                                                        :label="item.name"
                                                        :value="item.code"
                                                    ></el-option>
                                                </el-select>
                                </div>
                                <div class="items">
                                    <div class="leftname"><span>*</span> 偏移量：</div>
                                    <el-input v-model="variableParameter.offset" ></el-input>
                                </div>
                                <div class="items">
                                    <div class="leftname"><span>*</span> 零死区：</div>
                                    <el-input v-model="variableParameter.zero" ></el-input>
                                </div>
                                <!-- <div class="items">
                                    <div class="leftname"><span>*</span> 存储周期：</div>
                                    <el-input v-model="variableParameter.zero" ></el-input>
                                </div> -->
                                <div class="items">
                                    <div class="leftname"><span>*</span> 小数点位：</div>
                                    <el-input v-model="variableParameter.decimal" ></el-input>
                                </div>
                                
                            </div>
                        </div>
                        <div class="xiaotitle">
                             <span></span>条件存储
                        </div>
                        <div class="leftandrightdialog">
                            <div class="leftdio" style="margin-right:20px">
                                <div class="items">
                                    <div class="leftname"><span>*</span> 条件存储：</div>
                                    <el-select v-model="variableParameter.condition_type" placeholder="请选择">
                                                <el-option
                                                      v-for="item in conditiontypeGroup"
                                                      :key="item.value"
                                                      :label="item.name"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                                </div>
                                  <div class="items">
                                    <div class="leftname"><span>*</span> 参考值变量：</div>
                                    <el-input v-model="variableParameter.variable_id" ></el-input>
                                </div>
                            </div>
                            <div class="leftdio">
                                <div class="items">
                                    <div class="leftname"><span>*</span> 最大参考值：</div>
                                    <el-input v-model="variableParameter.max_ref_value" ></el-input>
                                </div>
                                  <div class="items">
                                    <div class="leftname"><span>*</span> 最小参考值：</div>
                                    <el-input v-model="variableParameter.min_ref_value" ></el-input>
                                </div>
                            </div>
                        </div>
                        <div class="xiaotitle">
                             <span></span>异常报警
                        </div>
                        <!-- <div class="leftandrightdialog">
                            <div class="leftdio" style="margin-right:20px">
                                <div class="items">
                                    <div class="leftname"><span>*</span> 越限类型：</div>
                                    <el-select v-model="variableParameter.event_over_limit" placeholder="请选择">
                                                <el-option
                                                      v-for="item in yuexiangList"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                                </div>
                                 
                            </div>
                            <div class="leftdio">
                                <div class="items">
                                    <div class="leftname"><span>*</span> 报警类型：</div>
                                     <el-select v-model="variableParameter.event_alert_type" placeholder="请选择">
                                                <el-option
                                                      v-for="item in yuexiangList"
                                                      :key="item.value"
                                                      :label="item.label"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                                </div>
                                 
                            </div>
                        </div> -->
                        <div class="xiaotitle">
                             <span></span>配置属性
                        </div>
                        <div class="check-item2">
                              <div class="input-item"> 
                                <div class="leftname">存盘</div>
                                <el-checkbox v-model="variableParameter.save"></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">是否取反</div>
                                <el-checkbox v-model="variableParameter.reverse"></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">报警打印</div>
                                <el-checkbox v-model="variableParameter.alarm_print"></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">更改提示</div>
                                <el-checkbox v-model="variableParameter.change_tip"></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">声音报警</div>
                                <el-checkbox v-model="variableParameter.audio_alarm"></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">合理值检查</div>
                                <el-checkbox v-model="variableParameter.value_check"></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">手动值</div>
                                <el-checkbox v-model="variableParameter.manual_value"></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">采样有效</div>
                                <el-checkbox v-model="variableParameter.sampling"></el-checkbox>
                            </div>
                        </div>

                    </div>
                    <div class="el-loading-mask" v-show="isMask">
                            <div class="el-loading-spinner">
                                <svg viewBox="25 25 50 50" class="circular">
                                    <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
                                </svg>
                           </div>
                    </div>
                   <template #footer >
                      <div class="dialog-footer">
                            <el-button  @click="addDecivebian = false" >取 消</el-button>
                            <el-button  class="last-el-button" @click="saveVariableFN" type="primary">确 定</el-button>
                      </div>
                    </template>
        </el-dialog>
        
        <!-- 批量修改变量 -->
        <el-dialog width="1000px" draggable  title="批量修改变量" :close-on-click-modal='false' v-model="piliangEdit">
                    <div class="addDecivebian">
                        <div class="xiaotitle">
                             <span></span>基础属性
                        </div>
                        <div class="leftandrightdialog">
                            <div class="leftdio" style="margin-right:20px">
                                
                                <div class="items">
                                    <div class="leftname"><el-checkbox v-model="batch.coefficient"></el-checkbox> 转换系数：</div>
                                    <el-input v-model="variableParameter.coefficient" :disabled='!batch.coefficient'></el-input>
                                </div>
                                <div class="items">
                                    <div class="leftname"><el-checkbox v-model="batch.data_type"></el-checkbox>数据类型：</div>
                                    <el-select v-model="variableParameter.data_type" :disabled='!batch.data_type' placeholder="请选择">
                                                    <el-option
                                                        v-for="item in optionsType"
                                                        :key="item.value"
                                                        :label="item.name"
                                                        :value="item.value"
                                                    ></el-option>
                                                </el-select>
                                </div>
                            


                            </div>
                            <div class="leftdio">
                               
                                <div class="items">
                                    <div class="leftname"><el-checkbox v-model="batch.offset"></el-checkbox>偏移量：</div>
                                    <el-input v-model="variableParameter.offset" :disabled='!batch.offset'></el-input>
                                </div>
                                <div class="items">
                                    <div class="leftname"><el-checkbox v-model="batch.zero"></el-checkbox>零死区：</div>
                                    <el-input v-model="variableParameter.zero" :disabled='!batch.zero'></el-input>
                                </div>
                              
                                
                            </div>
                        </div>
                        <div class="xiaotitle">
                             <el-checkbox v-model="batch.max_value"></el-checkbox><span style="margin-left:6px"></span>合理值
                        </div>
                        <div class="leftandrightdialog">
                            <div class="leftdio" style="margin-right:20px">
                                 <div class="items">
                                    <div class="leftname">最大合理值：</div>
                                    <el-input v-model="variableParameter.max_value" :disabled='!batch.max_value'></el-input>
                                </div>
                                
                                 
                            </div>
                            <div class="leftdio">
                                <div class="items">
                                    <div class="leftname">最小合理值：</div>
                                    <el-input v-model="variableParameter.min_value" :disabled='!batch.max_value'></el-input>
                                </div>
                                 
                            </div>
                        </div>
                        <div class="xiaotitle">
                            <el-checkbox v-model="batch.app_type_group"></el-checkbox><span style="margin-left:6px"></span>应用类型
                        </div>
                        <div class="leftandrightdialog">
                            <div class="leftdio" style="margin-right:20px">
                                 <div class="items">
                                    <div class="leftname">应用类型组：</div>
                                    <el-select v-model="variableParameter.app_type_group" :disabled='!batch.app_type_group' clearable filterable placeholder="请选择"  @change="getApplicationTypefn(variableParameter.app_type_group);variableParameter.app_type = ''">
                                                    <el-option
                                                        v-for="item in typeGroup"
                                                        :key="item.code"
                                                        :label="item.name"
                                                        :value="item.code"
                                                    ></el-option>
                                                </el-select>
                                </div>
                                
                                 
                            </div>
                            <div class="leftdio">
                                <div class="items">
                                    <div class="leftname">应用类型：</div>
                                    <el-select v-model="variableParameter.app_type" :disabled='!batch.app_type_group' clearable filterable placeholder="请选择">
                                                    <el-option
                                                        v-for="item in yingdataTypeList"
                                                        :key="item.code"
                                                        :label="item.name"
                                                        :value="item.code"
                                                    ></el-option>
                                                </el-select>
                                </div>
                                 
                            </div>
                        </div>
                        <div class="xiaotitle">
                            <el-checkbox v-model="batch.condition_type"></el-checkbox><span style="margin-left:6px"></span>条件存储
                        </div>

                        <div class="leftandrightdialog">
                            <div class="leftdio" style="margin-right:20px">
                                <div class="items">
                                    <div class="leftname">条件存储：</div>
                                    <el-select v-model="variableParameter.condition_type" :disabled='!batch.condition_type' placeholder="请选择">
                                                <el-option
                                                      v-for="item in conditiontypeGroup"
                                                      :key="item.value"
                                                      :label="item.name"
                                                      :value="item.value"
                                                 ></el-option>
                                            </el-select>
                                </div>
                                  <div class="items">
                                    <div class="leftname">参考值变量：</div>
                                    <el-input v-model="variableParameter.variable_id" :disabled='!batch.condition_type'></el-input>
                                </div>
                            </div>
                            <div class="leftdio">
                                <div class="items">
                                    <div class="leftname">最大参考值：</div>
                                    <el-input v-model="variableParameter.max_ref_value" :disabled='!batch.condition_type'></el-input>
                                </div>
                                  <div class="items">
                                    <div class="leftname">最小参考值：</div>
                                    <el-input v-model="variableParameter.min_ref_value" :disabled='!batch.condition_type'></el-input>
                                </div>
                            </div>
                        </div>
                        
                        
                        <div class="xiaotitle">
                            <el-checkbox v-model="batch.save"></el-checkbox><span style="margin-left:6px"></span>配置属性
                        </div>
                        <div class="check-item2">
                              <div class="input-item"> 
                                <div class="leftname">存盘</div>
                                <el-checkbox v-model="variableParameter.save" :disabled='!batch.save'></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">是否取反</div>
                                <el-checkbox v-model="variableParameter.reverse" :disabled='!batch.save'></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">报警打印</div>
                                <el-checkbox v-model="variableParameter.alarm_print" :disabled='!batch.save'></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">更改提示</div>
                                <el-checkbox v-model="variableParameter.change_tip" :disabled='!batch.save'></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">声音报警</div>
                                <el-checkbox v-model="variableParameter.audio_alarm" :disabled='!batch.save'></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">合理值检查</div>
                                <el-checkbox v-model="variableParameter.value_check" :disabled='!batch.save'></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">手动值</div>
                                <el-checkbox v-model="variableParameter.manual_value" :disabled='!batch.save'></el-checkbox>
                            </div>
                            <div class="input-item"> 
                                <div class="leftname">采样有效</div>
                                <el-checkbox v-model="variableParameter.sampling" :disabled='!batch.save'></el-checkbox>
                            </div>
                        </div>

                    </div>
                    <div class="el-loading-mask" v-show="isMask">
                            <div class="el-loading-spinner">
                                <svg viewBox="25 25 50 50" class="circular">
                                    <circle cx="50" cy="50" r="20" fill="none" class="path"></circle>
                                </svg>
                           </div>
                    </div>
                   <template #footer >
                      <div class="dialog-footer">
                            <el-button  @click="piliangEdit = false" >取 消</el-button>
                            <el-button  class="last-el-button" @click="piliangEditfn" type="primary">确 定</el-button>
                      </div>
                    </template>
        </el-dialog>
       
        
        <div class="el-loading-mask" v-show="isMask">
             <div class="el-loading-spinner"><svg viewBox="25 25 50 50" class="circular"> <circle cx="50" cy="50" r="20" fill="none" class="path"></circle></svg></div>
          </div>
       

    </div>
</template>

<script>
import {findchannelconfigAll,getChannelAndDeviceState} from "../api/dataComparisonApi";
import { useCounterStore } from '../stores/counter'
import {getDeviceList,commondatatype,getVariablesDevice,commonAppTypeGroup,addVariables,editVariables,batchEditVariables,delVariables,batchDelVariables} from "../api/Interface";
export default {


    data() {
        return {
            //搜索
            search:{
                "device_name":"",
                "app_type_group":"",
                "app_type":"",
            },
            //批量修改
            batch:{
                coefficient:false,
                data_type:false,
                offset:false,
                zero:false,
                max_value:false,
                app_type_group:false,
                condition_type:false,
                save:false,
            },
            isMask:false,
            tabindex:1,
             total:0,
            currentPage:1,
            data_bitsList:[],
            yuexiangList:[],
            deviceArr:[],//所有设备
            leftTable:[],//变量列表
            leftTableCopy:[],
            // optionsType:[],//数据类型
            optionsFang:[
                  {
                    'name':"读",
                    'value':1,
                },
                  {
                    'name':"写",
                    'value':2,
                },
                  {
                    'name':"读写",
                    'value':3,
                },
            ],
            yingdataTypeList:[],
            versionsName:"",
            dataList:[
                {
                    'treeName':"采集通道",
                    'children':[],
                    'mytype':"channel",
                    'myid':10000000001
                },
                {
                'treeName':"状态量",
                'children':[
                    {
                        'treeName':"channelstate",
                        'children':[],
                        'mytype':"device",
                        'myid':1000000000003
                    },
                    {
                        'treeName':"devicestate",
                        'children':[],
                        'mytype':"device",
                        'myid':1000000000004
                    },
                ],
                'mytype':"channel",
                'myid':1000000000002
            },
           ],
           channelstateList:[],
         devicestateList:[],
            defaultProps: {
                children: 'children',
                label: 'treeName',
            },
            nowDeviceItem:{},//当前选中的树形
            typeGroup:[],//应用类型组
            typeGroupAll:[],
            conditiontypeGroup:[
                {
                    'name':"无条件存储",
                    'value':1,
                },
                {
                    'name':"小于最小参考值时存储",
                    'value':2,
                },
                {
                    'name':"等于最小参数值时存储",
                    'value':3,
                },
                {
                    'name':"大于最小参考值且小于最大参考值时存",
                    'value':4,
                },
                {
                    'name':"大于参考值时存储",
                    'value':5,
                },
              
            ],//条件类型组
            variableParameter:{
                'name':"",
                'value':"",
                'access':"",
                'condition_type':"",
                'min_ref_value':"",
                'max_ref_value':"",
                'variable_id':0,
                'data_type':"",
                'app_type_group':"",
                'app_type':1,
                'max_value':"",
                'min_value':"",
                'decimal':"",
                'coefficient':"",
                'offset':"",
                'zero':"",
                'event_alert_type':1,
                'event_over_limit':1,
                'lock':false,
                'save':false,
                'audio_alarm':false,
                'alarm_print':false,
                'manual_value':false,
                'reverse':false,
                'value_check':false,
                'change_tip':false,
                'sampling':false,
            },//变量参数
            deviceTypecaozuo:"新增变量",
            addDecive:false,//变量编辑
            checked:true,
            addDecivebian:false,//新增变量
            piliangEdit:false,//批量修改
            multipleSelection:[]

        };
    },

    mounted() {
       
        this.getcommonAppTypeGroup()
        // this.getcommondatatype()
        this.getDeviceListData()
    },
    computed: {
       optionsType(){
         return useCounterStore().mydataType
       },
    },

    methods: {
         //搜索
        searchFN(){
             var filterArr = this.leftTableCopy.filter(item => item.name.includes(this.search.device_name))
           
             filterArr = filterArr.filter(item => String(item.app_type_group).includes(this.search.app_type_group))
             filterArr = filterArr.filter(item => String(item.app_type).includes(this.search.app_type))

             this.leftTable = filterArr
             this.total = this.leftTable.length
        },
        //重置搜索
        chongzhifn(){
            this.search = {
                device_name:"",
                app_type_group:"",
                app_type:"",
            }
            this.leftTable = this.leftTableCopy
        },
        handleSizeChangejiao(){
            
        },
        handleCurrentChangejiao(val){
           this.currentPage=val;
           this.leftTable = this.getCurrentPageData(this.leftTableCopy,this.currentPage,100)
        },
        getCurrentPageData(dataList, page, size) {
            // 计算并返回当前页数据
            var res = dataList.slice((page-1)*size, page*size)
            return res
        },
        //获取数据类型
        getcommondatatype(){
            commondatatype().then(res => {
                // console.log("数据类型",res);
                  this.optionsType = res
            })
        },
        //获取应用类型组
        getcommonAppTypeGroup(){
            commonAppTypeGroup().then(res => {
                //   this.typeGroup = res
                if(res != undefined){
                     this.typeGroupAll = res
                    //  console.log("应用类型组",this.typeGroupAll);
                     this.typeGroup = res.filter(item => item.pid === 0)
                }
            })
        },
         //根据应用类型组获取应用类型
        getApplicationTypefn(val){
            if(val == undefined){
               this.variableParameter.app_type_group = ""
               this.variableParameter.app_type = ""
               return
            }
            //  this.variableParameter.app_type = ""
            var arr1 = this.typeGroup.filter(item => item.code === val)
            this.yingdataTypeList = this.typeGroupAll.filter(item => item.pid === arr1[0].id)
            // console.log("this.yingdataTypeList",this.yingdataTypeList);
        },
          //获取表格列表
        getfindchannelconfigAll(){
            findchannelconfigAll().then(res => {
            this.isMask = false
            if(res != undefined){
                res.forEach((item,index) => {
                     item.treeName = item.channel_name
                     item.mytype = 'channel'
                     item.myid = 10000000+index
                     item.children = this.deviceArr.filter(tt => tt.channel_number == item.channel_number)
                })
                this.dataList[0].children = res
                getChannelAndDeviceState().then(result => {
                    if(res != undefined){
                        this.channelstateList = result.filter(item => item.name.includes('channelstate'))
                        this.devicestateList = result.filter(item => item.name.includes('devicestate'))
                        //  console.log("result",result);

                     }
                })
                // console.log("this.dataList",this.dataList);
            }
            
            }).catch(() => {
                  this.isMask = false
              })
        },
        //获取所有设备
        getDeviceListData(){
             this.isMask = true
              getDeviceList().then(res => {
                   if(res != undefined){
                    res.forEach((item,index) => {
                         item.treeName = item.device_name
                         item.children = []
                         item.mytype = 'device'
                         item.myid = 1000000+index
                    })
                       this.deviceArr = res
                       this.getfindchannelconfigAll()
                   }
              }).catch(() => {
                  this.isMask = false
              })
        },
        //树形结构点击
        treeClick(row){
            //  console.log("树形",row);
             this.nowDeviceItem = row
            var arr1 = []
            var arr2 = []
            var arr3 = []
            var arr4 = []
            var arr5 = []
             if(row.mytype == 'device'){
                if(row.treeName == 'channelstate' && row.myid == '1000000000003'){
                    var findArr = []

                    this.channelstateList.forEach(item => {
                         arr1 = this.optionsType.filter(tt => tt.value == item.data_type)
                            arr2 = this.optionsFang.filter(tt => tt.value == item.access)
                            arr3 = this.typeGroup.filter(tt => tt.code == item.app_type_group)
                             item.lock = item.lock == 1 ? true : false
                             item.save = item.save == 1 ? true : false
                             item.audio_alarm = item.audio_alarm == 1 ? true : false
                             item.alarm_print = item.alarm_print == 1 ? true : false
                             item.manual_value = item.manual_value == 1 ? true : false
                             item.reverse = item.reverse == 1 ? true : false
                             item.value_check = item.value_check == 1 ? true : false
                             item.change_tip = item.change_tip == 1 ? true : false
                             item.sampling = item.sampling == 1 ? true : false
                             item.data_type_name = arr1.length != 0 ? arr1[0].name : ""
                             item.access_name = arr2.length != 0 ? arr2[0].name : ""
                             item.app_type_group_name = arr3.length != 0 ? arr3[0].name : ""
                             if(arr3.length != 0){
                                arr4 = this.typeGroupAll.filter(tt => tt.pid == arr3[0].id)
                                arr5 = arr4.filter(tt => tt.code == item.app_type)
                             }
                             item.app_type_name = arr5.length != 0 ? arr5[0].name : ""
                    })
                    this.currentPage = 1 
                    this.leftTableCopy = JSON.parse(JSON.stringify(this.channelstateList)) 
                    this.leftTable = this.getCurrentPageData(this.leftTableCopy,this.currentPage,100)
                    this.total = this.leftTableCopy.length
                    return
                }
                if(row.treeName == 'devicestate' && row.myid == '1000000000004'){
                    var findArr = []
                    this.devicestateList.forEach(item => {
                         arr1 = this.optionsType.filter(tt => tt.value == item.data_type)
                            arr2 = this.optionsFang.filter(tt => tt.value == item.access)
                            arr3 = this.typeGroup.filter(tt => tt.code == item.app_type_group)
                             item.lock = item.lock == 1 ? true : false
                             item.save = item.save == 1 ? true : false
                             item.audio_alarm = item.audio_alarm == 1 ? true : false
                             item.alarm_print = item.alarm_print == 1 ? true : false
                             item.manual_value = item.manual_value == 1 ? true : false
                             item.reverse = item.reverse == 1 ? true : false
                             item.value_check = item.value_check == 1 ? true : false
                             item.change_tip = item.change_tip == 1 ? true : false
                             item.sampling = item.sampling == 1 ? true : false
                             item.data_type_name = arr1.length != 0 ? arr1[0].name : ""
                             item.access_name = arr2.length != 0 ? arr2[0].name : ""
                             item.app_type_group_name = arr3.length != 0 ? arr3[0].name : ""
                             if(arr3.length != 0){
                                arr4 = this.typeGroupAll.filter(tt => tt.pid == arr3[0].id)
                                arr5 = arr4.filter(tt => tt.code == item.app_type)
                             }
                             item.app_type_name = arr5.length != 0 ? arr5[0].name : ""
                    })
                    this.currentPage = 1 
                    this.leftTableCopy = JSON.parse(JSON.stringify(this.devicestateList)) 
                    this.leftTable = this.getCurrentPageData(this.leftTableCopy,this.currentPage,100)
                    this.total = this.leftTableCopy.length
                    return
                }
                this.isMask = true
                if(this.deviceTypecaozuo == '新增变量'){
                    this.currentPage = 1
                }
                 getVariablesDevice(row.device_id).then(res => {
                     this.isMask =false
                      if(res != undefined){
                        
                    
                        res.forEach(item => {
                            arr1 = this.optionsType.filter(tt => tt.value == item.data_type)
                            arr2 = this.optionsFang.filter(tt => tt.value == item.access)
                            arr3 = this.typeGroup.filter(tt => tt.code == item.app_type_group)
                             item.lock = item.lock == 1 ? true : false
                             item.save = item.save == 1 ? true : false
                             item.audio_alarm = item.audio_alarm == 1 ? true : false
                             item.alarm_print = item.alarm_print == 1 ? true : false
                             item.manual_value = item.manual_value == 1 ? true : false
                             item.reverse = item.reverse == 1 ? true : false
                             item.value_check = item.value_check == 1 ? true : false
                             item.change_tip = item.change_tip == 1 ? true : false
                             item.sampling = item.sampling == 1 ? true : false
                             item.data_type_name = arr1.length != 0 ? arr1[0].name : ""
                             item.access_name = arr2.length != 0 ? arr2[0].name : ""
                             item.app_type_group_name = arr3.length != 0 ? arr3[0].name : ""
                             if(arr3.length != 0){
                                arr4 = this.typeGroupAll.filter(tt => tt.pid == arr3[0].id)
                                arr5 = arr4.filter(tt => tt.code == item.app_type)
                             }
                             item.app_type_name = arr5.length != 0 ? arr5[0].name : ""
                             
                        })
                        
                        this.leftTableCopy = JSON.parse(JSON.stringify(res))
                        this.leftTable = this.getCurrentPageData(this.leftTableCopy,this.currentPage,100)
                        this.total = res.length
                      }
                 })
             }
        },
        //新增变量
        addDecivebianfn(){
            // console.log("this.nowDeviceItem",this.nowDeviceItem);
            if(this.nowDeviceItem.mytype != 'device'){
                 this.$message({showClose: true,message: '请选择设备',type: 'warning'});
                 return
            }
            var arr2 = this.typeGroup.filter(item => item.name == '未定义')
            var app_type_group = ""
            var app_typeArr = []
            if(this.typeGroup.length != 0 && arr2.length != 0){
                app_type_group = arr2[0].code
                 this.getApplicationTypefn(app_type_group)
                 app_typeArr = this.typeGroupAll.filter(item => item.pid != 0 && item.pid === arr2[0].id)
            }
            this.variableParameter = {
                'name':"",
                'value':"0",
                'access':this.optionsFang.length != 0 ? this.optionsFang[0].value : "",
                'condition_type':1,
                'min_ref_value':"0",
                'max_ref_value':"0",
                'variable_id':0,
                'data_type':this.optionsType.length != 0 ? this.optionsType[0].value : "",
                'app_type_group':app_type_group,
                'app_type':app_typeArr.length == 0 ? "" : app_typeArr[0].code,
                'max_value':"0",
                'min_value':"0",
                'decimal':"1",
                'coefficient':"0",
                'offset':"0",
                'zero':"0",
                'event_alert_type':1,
                'event_over_limit':1,
                'lock':false,
                'save':true,
                'audio_alarm':true,
                'alarm_print':false,
                'manual_value':false,
                'reverse':false,
                'value_check':false,
                'change_tip':false,
                'sampling':true,
            }
            this.deviceTypecaozuo = '新增变量'
            this.addDecivebian = true
        },
        //修改变量
        editFN(row){
            this.variableParameter = JSON.parse(JSON.stringify(row))
            this.deviceTypecaozuo = `修改变量(${row.name})`
            this.getApplicationTypefn(row.app_type_group)
            this.addDecivebian = true
        },
        //确定添加/修改变量
        saveVariableFN(){
            if(this.variableParameter.name === ""){
                this.$message({showClose: true,message: '变量名称不能为空',type: 'warning'});
                return
            }
            if(this.variableParameter.value === ""){
                this.$message({showClose: true,message: '当前值不能为空',type: 'warning'});
                return
            }
            if(this.variableParameter.access === ""){
                this.$message({showClose: true,message: '请选择访问类型',type: 'warning'});
                return
            }
            if(this.variableParameter.condition_type === ""){
                this.$message({showClose: true,message: '请选择条件类型',type: 'warning'});
                return
            }
            if(this.variableParameter.min_ref_value === ""){
                this.$message({showClose: true,message: '最小参考值不能为空',type: 'warning'});
                return
            }
            if(this.variableParameter.max_ref_value === ""){
                this.$message({showClose: true,message: '最大参考值不能为空',type: 'warning'});
                return
            }
            if(this.variableParameter.variable_id === ""){
                this.$message({showClose: true,message: '参考值变量不能为空',type: 'warning'});
                return
            }
            if(this.variableParameter.data_type === ""){
                this.$message({showClose: true,message: '请选择数据类型',type: 'warning'});
                return
            }
            if(this.variableParameter.app_type_group === ""){
                this.$message({showClose: true,message: '请选择应用类型组',type: 'warning'});
                return
            }
            if(this.variableParameter.app_type === ""){
                this.$message({showClose: true,message: '请选择应用类型',type: 'warning'});
                return
            }
            if(this.variableParameter.max_value === ""){
                this.$message({showClose: true,message: '最大合理值不能为空',type: 'warning'});
                return
            }
            if(this.variableParameter.min_value === ""){
                this.$message({showClose: true,message: '最小合理值不能为空',type: 'warning'});
                return
            }
            if(this.variableParameter.decimal === ""){
                this.$message({showClose: true,message: '小数点位不能为空',type: 'warning'});
                return
            }
            if(this.variableParameter.coefficient === ""){
                this.$message({showClose: true,message: '转换系数不能为空',type: 'warning'});
                return
            }
            if(this.variableParameter.offset === ""){
                this.$message({showClose: true,message: '偏移量不能为空',type: 'warning'});
                return
            }
            if(this.variableParameter.zero === ""){
                this.$message({showClose: true,message: '零死区不能为空',type: 'warning'});
                return
            }
            if(this.variableParameter.event_alert_type === ""){
                this.$message({showClose: true,message: '请选择报警类型',type: 'warning'});
                return
            }
            if(this.variableParameter.event_over_limit === ""){
                this.$message({showClose: true,message: '请选择越限类型',type: 'warning'});
                return
            }
            var d = {
                "name": this.variableParameter.name,
                "device_name":this.nowDeviceItem.device_name,
                "fullName":this.nowDeviceItem.device_name+"."+this.variableParameter.name,
                "value": Number(this.variableParameter.value),
                "access": Number(this.variableParameter.access),
                "lock": this.variableParameter.lock ? 1 : 0,
                "condition_type": Number(this.variableParameter.condition_type),
                "min_ref_value": Number(this.variableParameter.min_ref_value),
                "max_ref_value": Number(this.variableParameter.max_ref_value),
                "variable_id": Number(this.variableParameter.variable_id),
                "device_id": Number(this.nowDeviceItem.device_id),
                "data_type": Number(this.variableParameter.data_type),
                "save": this.variableParameter.save ? 1 : 0,
                "audio_alarm": this.variableParameter.audio_alarm ? 1 : 0,
                "alarm_print": this.variableParameter.alarm_print ? 1 : 0,
                "manual_value": this.variableParameter.manual_value ? 1 : 0,
                "reverse": this.variableParameter.reverse ? 1 : 0,
                "value_check": this.variableParameter.value_check ? 1 : 0,
                "change_tip": this.variableParameter.change_tip ? 1 : 0,
                "sampling": this.variableParameter.sampling ? 1 : 0,
                "app_type_group": Number(this.variableParameter.app_type_group),
                "app_type":  Number(this.variableParameter.app_type),
                "max_value": Number(this.variableParameter.max_value),
                "min_value": Number(this.variableParameter.min_value),
                "decimal": Number(this.variableParameter.decimal),
                "coefficient": Number(this.variableParameter.coefficient),
                "offset": Number(this.variableParameter.offset),
                "zero": Number(this.variableParameter.zero),
                // 'number':1,
                'event_alert_type':1,
                'event_over_limit':1,
                'channel_number':this.nowDeviceItem.channel_number,
                'device_number':this.nowDeviceItem.device_number,
            }
 
             this.isMask = true
            if(this.deviceTypecaozuo == '新增变量'){
                var arr1 = this.leftTableCopy.filter(item => item.name == this.variableParameter.name)
                if(arr1.length != 0){
                    this.isMask = false
                    this.$message({showClose: true,message: '变量名称已重复，请重新更换！',type: 'warning'});
                    return
                }
                addVariables(d).then(res => {
                      this.isMask = false
                      if(res.code == 200){
                              this.addDecivebian = false
                                 this.$message({showClose: true,message: '新增成功',type: 'success'});
                                 this.treeClick(this.nowDeviceItem)
                     }else {
                                this.$message({showClose: true,message: '新增失败',type: 'error'});
                    }
                }).catch(() => {
                         this.isMask = false
                })
            }else {
                 d.id = this.variableParameter.id

                 var arr1 = this.leftTableCopy.filter(item => item.id != this.variableParameter.id)
                 var arr2 = arr1.filter(item => item.name == this.variableParameter.name)
                 if(arr2.length != 0){
                    this.isMask = false
                    this.$message({showClose: true,message: '变量名称已重复，请重新更换！',type: 'warning'});
                    return
                 }
                 editVariables(d).then(res => {
                      this.isMask = false
                      if(res.code == 200){
                              this.addDecivebian = false
                                 this.$message({showClose: true,message: '修改成功',type: 'success'});
                                 this.treeClick(this.nowDeviceItem)
                     }else {
                                this.$message({showClose: true,message: '修改失败',type: 'error'});
                    }
                }).catch(() => {
                         this.isMask = false
                })
            }
        },
        //删除变量
        delVariablesfn(row){
             this.$confirm(`是否要删除此变量吗？`,'提示',{
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
                this.isMask = true
               delVariables(row.id).then(res => {
                   this.isMask = false
                  if(res.code == 200){
                    this.$message({showClose: true,message: '删除成功',type: 'success'});
                     this.treeClick(this.nowDeviceItem)
                  }else {
                     this.$message.error('删除失败！！')
                  }
               }).catch(error => {
                   this.isMask = false
                    this.$message.error('删除失败！！')
               })
              
        
                      
            }).catch(() => {
              // ...
            });
        },
        //选择设备
        handleSelectionChange(val){
            // console.log("选择设备",val);
            this.multipleSelection = val
        },
        //打开批量修改
        openPiliangEdit(){
            if(this.multipleSelection.length === 0){
                this.$message({showClose: true,message: '请选择需要修改的变量',type: 'warning'});
                return
            }
            this.variableParameter = {
                'name':"",
                'value':"",
                'access':"",
                'condition_type':"",
                'min_ref_value':"",
                'max_ref_value':"",
                'variable_id':0,
                'data_type':"",
                'app_type_group':0,
                'app_type':0,
                'max_value':"",
                'min_value':"",
                'decimal':"",
                'coefficient':"",
                'offset':"",
                'zero':"",
                'event_alert_type':1,
                'event_over_limit':1,
                'lock':false,
                'save':false,
                'audio_alarm':false,
                'alarm_print':false,
                'manual_value':false,
                'reverse':false,
                'value_check':false,
                'change_tip':false,
                'sampling':false,
            }
            this.batch = {
                coefficient:false,
                data_type:false,
                offset:false,
                zero:false,
                max_value:false,
                app_type_group:false,
                condition_type:false,
                save:false,
            }
            this.piliangEdit = true
        },
        //批量修改变量
        piliangEditfn(){

            // console.log("批量修改变量参数",this.variableParameter);
            var arr1 = []
            this.multipleSelection.forEach(item => {
                 arr1.push({
                    "id":item.id,
                    "name": item.name,
                    "fullName":this.nowDeviceItem.device_name+"."+item.name,
                    "value": item.value,
                    "device_name":this.nowDeviceItem.device_name,
                    "access": item.access,
                    "lock": item.lock ? 1 : 0,
                    "condition_type": item.condition_type,
                    "min_ref_value": item.min_ref_value,
                    "max_ref_value": item.max_ref_value,
                    "variable_id": item.variable_id,
                    "device_id": item.device_id,
                    "data_type": item.data_type,
                    "save": item.save ? 1 : 0,
                    "audio_alarm": item.audio_alarm ? 1 : 0,
                    "alarm_print": item.alarm_print ? 1 : 0,
                    "manual_value": item.manual_value ? 1 : 0,
                    "reverse": item.reverse ? 1 : 0,
                    "value_check": item.value_check ? 1 : 0,
                    "change_tip": item.change_tip ? 1 : 0,
                    "sampling": item.sampling ? 1 : 0,
                    "app_type_group": item.app_type_group,
                    "app_type":  item.app_type,
                    "max_value": item.max_value,
                    "min_value": item.min_value,
                    "decimal": item.decimal,
                    "coefficient": item.coefficient,
                    "offset": item.offset,
                    "zero": item.zero,
                    'event_alert_type':1,
                    'event_over_limit':1,
                    'device_number':item.device_number,
                    'channel_number':item.channel_number,
                })
            })
            

            arr1.forEach(item => {
                if(this.batch.coefficient){
                    item.coefficient = this.variableParameter.coefficient == "" ? "" : Number(this.variableParameter.coefficient)
                }
                if(this.batch.data_type){
                    item.data_type = this.variableParameter.data_type == "" ? "" : Number(this.variableParameter.data_type)
                }
                if(this.batch.offset){
                    item.offset = this.variableParameter.offset == "" ? "" : Number(this.variableParameter.offset)
                }
                if(this.batch.zero){
                    item.zero = this.variableParameter.zero == "" ? "" : Number(this.variableParameter.zero)
                }
                if(this.batch.max_value){
                    item.max_value = this.variableParameter.max_value == "" ? "" : Number(this.variableParameter.max_value)
                    item.min_value = this.variableParameter.min_value == "" ? "" : Number(this.variableParameter.min_value)
                }
                if(this.batch.app_type_group){
                    item.app_type_group = this.variableParameter.app_type_group == "" ? "" : Number(this.variableParameter.app_type_group)
                    item.app_type = this.variableParameter.app_type == "" ? "" : Number(this.variableParameter.app_type)
                }
                if(this.batch.condition_type){
                    item.condition_type = this.variableParameter.condition_type == "" ? "" : Number(this.variableParameter.condition_type)
                    item.variable_id = this.variableParameter.variable_id == "" ? "" : Number(this.variableParameter.variable_id)
                    item.max_ref_value = this.variableParameter.max_ref_value == "" ? "" : Number(this.variableParameter.max_ref_value)
                    item.min_ref_value = this.variableParameter.min_ref_value == "" ? "" : Number(this.variableParameter.min_ref_value)
                }
                if(this.batch.save){
                    item.save = item.save ? 1 : 0
                    item.reverse = item.reverse ? 1 : 0
                    item.alarm_print = item.alarm_print ? 1 : 0
                    item.change_tip = item.change_tip ? 1 : 0
                    item.audio_alarm = item.audio_alarm ? 1 : 0
                    item.value_check = item.value_check ? 1 : 0
                    item.manual_value = item.manual_value ? 1 : 0
                    item.sampling = item.sampling ? 1 : 0
                }
            })
            // console.log("批量修改变量参数",arr1);
            batchEditVariables(arr1).then(res => {
                //  console.log("批量修改",res);
                 if(res.code == 200){
                     this.piliangEdit = false
                    this.$message({showClose: true,message: '修改成功',type: 'success'});
                     this.treeClick(this.nowDeviceItem)
                 }else {
                     this.$message({showClose: true,message: '修改失败',type: 'error'});
                 }
            })

        },
        //批量删除变量
        delMordfn(){
            if(this.multipleSelection.length === 0){
                this.$message({showClose: true,message: '请选择需要删除的变量',type: 'warning'});
                return
            }
            this.$confirm(`确定要删除选中的变量吗？`,'提示',{
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {
                var arr1 = []
                this.multipleSelection.forEach(item => arr1.push(item.id))
                // console.log("删除的变量id",arr1);
               batchDelVariables(arr1).then(res => {
                  if(res.code == 200){
                     this.$message({showClose: true,message: '删除成功',type: 'success'});
                     this.treeClick(this.nowDeviceItem)
                  }else {
                      this.$message.error('删除失败！！')
                  }
               }).catch(error => {
                    this.$message.error('删除失败！！')
               })
              
        
                      
            }).catch(() => {
              // ...
            });

        },

    },
};
</script>

<style lang="scss" scoped>
.addDecivebian {
     padding: 12px 20px;
     
}
.el-dialog .leftandrightdialog {
    padding: 0px;
    .items{
     margin-bottom: 8px;
     :deep(.el-input){
        height: 28px;
     }
     :deep(.el-select) {
        height: 28px !important;
     }
     :deep(.el-select__wrapper){
        height: 28px !important;
     }
     .leftname {
         width: 90px;
         min-width: 90px;
         display: flex;
         align-items: center;
         justify-content: flex-end;
         :deep(.el-checkbox){
            margin-right: 6px;
         }
     }
   }

}
.topcon  { 
    display: flex;
    align-items: center;
    justify-content: space-between;
   
    .left-nav {
         display: flex;
         .nav-item {
             width: 96px;
             height: 34px;
             text-align: center;
             line-height: 36px;
             cursor: pointer;
             border: 1px solid #E6E6E6;
             color: #666666;
             
             &.active {
                 background-color: #fff;
                 color: #1A1A1A;
                 border-color: transparent;
             }
         }
    }
    .right-btn { 
        display: flex;
       

    }
    
}
 .btn-item {
             min-width: 72px;
             width: 72px;
             height: 30px;
             text-align: center;
             line-height: 30px;
             font-size: 12px;
             background-color: #2178F1;
             color: #FFF;
             border-radius: 4px;
             cursor: pointer;
        }
        .item1 {
             background-color: #E7F0FF;
             border: 1px solid #2178F1;
             color: #2178F1;
             box-sizing: border-box;
             margin-left: 8px;
        }
.variableediting {
     position: relative;
     overflow: hidden;
}
.con {
     width: 100%;
     height: calc(100% - 36px);
     background-color: #fff;
     box-sizing: border-box;
     padding: 12px 0px 0px 12px;
      position: relative;
     display: flex;
     .left-tree {
         width: 260px;
         height: 100%;
         border-right: 1px solid #E6E6E6;
         padding-right: 12px;
         box-sizing: border-box;

     }

     .right-table {
         width: calc(100% - 260px);
         height: calc(100% - 36px);
         box-sizing: border-box;
         .top-search {
             width: 100%;
             height: 34px;
             display: flex;
             padding-left: 12px;
             box-sizing: border-box;
            
          
             .search-item {
                display: flex;
                align-items: center;
                 height: 32px;
                 margin-right: 12px;
               
                 :deep(.el-input__inner){
                    height: 32px !important;
                    line-height: 32px !important;
                }
                :deep(.el-select){
                    height: 32px !important;
                }
                :deep(.el-select__wrapper){
                     height: 32px !important;
                }
                .leftname {
                     margin-right: 8px;
                     white-space: nowrap;
                }
             }
         }
         .lines {
             width: 100%;
             height: 1px;
             background-color: #E6E6E6;
             margin: 12px 0px;
         }
        .mi-table {
               width: 100%;
                height: calc(100% - 24px);
                margin-left: 12px;
                margin-bottom: 10px;
                padding-right: 12px;
                 box-sizing: border-box;
                 :deep(.el-input__inner) {
                     height: 28px;
                     line-height: 28px;
                 }
                 :deep(.el-input__icon) {
                     line-height: 28px;
                 }
               
                 .mysort {
                    display: flex;
                    align-items: center;
                    justify-content: center;
                 }
                 :deep(.el-table__fixed-right) {
                         bottom: 9px !important;
                 }
                 :deep(.el-switch.is-checked .el-switch__core) {
                     width: 24px !important;
                     height: 12px;
                 }
                 :deep(.el-switch__core) {
                       width: 24px !important;
                     height: 12px;
                 }
                 :deep(.el-switch.is-checked .el-switch__core::after) {
                     margin-left: -10px;
                 }
                 :deep(.el-switch__core:after) {
                          top: 0px;
                          width: 10px;
                          height: 10px;
                 }
             }
        .bot-btn {
             width: 100%;
             height: 47px;
            //  margin-top: 44px;
             border-top: 1px solid #E6E6E6;
             .scr-div {
                width: 100%;
                height: 48px;
                display: flex;
                align-items: center;
                justify-content: space-between;
             }
             
        }
        .right-paging {
             position: relative;
             :deep(.el-pagination__sizes) {
                    // position: absolute;
                    // right: 0;
                    // top: 3px;
                    margin-right: 0px;
                    .el-input__inner {
                         border-radius: 4px !important;
                    }
                   
             }
             :deep(.el-pagination__total) {
                 color: #999999;
                 margin-right: 1px;
             }
             :deep(.el-pager) {
                    li {
                                margin: 0px 2px !important;
                            }
                   .number,.el-icon-more {
                      background-color: #fff;
                    border: 1px solid #E6E6E6;
                    box-sizing: border-box;
                      border-radius: 4px;
                   }
                    
             }
             :deep(.el-pagination.is-background .btn-next) {
                background-color: #fff;
                border: 1px solid #E6E6E6;
                box-sizing: border-box;
                border-radius: 4px;
                i {
                    color: #666666;
                }
             }
              
             :deep(.btn-next) {
                    margin-right: 106px;
             }
        }
     }

}
.drawer-con {
      width: 100%;
      height: 100%;
       .drawer-top {
          width: 100%;
          height: 52px;
          padding: 20px 20px 0px 20px;
          box-sizing: border-box;
          border-bottom: 1px solid #EBEBEB;
          display: flex;
          justify-content: space-between;
          span {
             color: #1A1A1A;
             font-size: 16px;
          }
          i {
             font-size: 20px !important;
             position: relative;
             top: 2px;
              cursor: pointer;
          }
       }
       .drawer-middle {
          width: 100%;
          height: calc(100% - 116px);
          padding: 20px;
          box-sizing: border-box;
       }
       .drawer-bottom {
         width: 100%;
         height: 64px;
         border-top: 1px solid #E0EDFF;
         padding-top: 12px;
         box-sizing: border-box;
         display: flex;
         justify-content: center;
       }
}
.quxiao {
                         margin-left: 8px;
                         color: #666666;
                         background-color: #fff;
                         border: 1px solid #cccccc;
}
.xiaotitle {
     width: 100%;
     font-size: 12px;
     color: #333333;
     display: flex;
     align-items: center;
     margin-bottom: 12px;
     span {
         display: inline-block;
         width: 2px;
         height: 12px;
         background-color: #2178F1;
         margin-right: 6px;
     }
}
.input-item {
     display: flex;
     align-items: center;
     width: 100%;
     height: 44px;
     .leftname {
         width: 72px;
         text-align: right;
         font-size: 12px;
         color: #666666;
         margin-right: 8px;
         span {
             color: #FF0000;
             margin-right: 1px;
         }
     }
     :deep(.el-input__inner){
         height: 28px;
         line-height: 28px;
     }
     .tips {
          font-size: 12px;
          color: #666666;
          margin-left: 8px;
     }
     

}
.check-item {
     width: 100%;
     display: flex;
     flex-wrap: wrap;
     .input-item {
         width: 50%;
     }
}
.check-item2 {
      width: 100%;
     display: flex;
     flex-wrap: wrap;
     .input-item {
         width: 25%;
     }
}
 .bot-btn {
            width: 100%;
            height: 60px;
            display: flex;
            padding: 0px 12px;
            align-items: center;
            box-sizing: border-box;
            .scr-div {
                 width: 100%;
                  height: 60px;
                display: flex;
                align-items: center;
                justify-content: space-between;
            }
 }
 .left-btn {
             display: flex;
             align-items: center;
 }
  .btn-items { 
                width: 84px;
                // padding: 0px 8px;
                box-sizing: border-box;
                height: 28px;
                display: flex;
                align-items: center;
                justify-content: center;
                border-radius: 4px;
                // box-sizing: border-box;
                img {
                     margin-left: 4px;
                }
 }
  .qi-btn {
                border: 1px solid #2178F1;
                color: #2178F1;
             }
             .del-btn {
                border: 1px solid #EE422B;
                color: #EE422B;
             }
</style>